<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/javascript" src="__ROOT__/Public/Js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="__ROOT__/Public/Js/core.js"></script>
  </head>
  <body>
    <div id="content">

      <volist name="list" id="volist" key="i">
        <ul>
          <li>
            <a href="javascript:void(0)" display="1" onclick="clickLink(this)">{$setting[$i]}</a>
          <if condition="$volist.check eq 1"><input type="checkbox" checked="checked" onclick="clickLevel1(this)"/>
            <else/><input type="checkbox" onclick="clickLevel1(this)" />
          </if>
          <ul>
            <volist name="volist.classify" id="vol" key="j">
              <li>{$vol.title}
              <if condition="$vol.check eq 1"><input type="checkbox" checked="checked" cid="{$vol.id}" type_id="{$i}" onclick="clickLevel2(this)"/>
                <else/><input type="checkbox" cid="{$vol.id}" type_id="{$i}" onclick="clickLevel2(this)" />
              </if>
              </li>
            </volist>
          </ul>
          </li>
        </ul>
      </volist>

      <form method="post" action="__URL__/settingSave">
        <input id="hids" type="hidden" name="hids" value="" />
        <input id="zids" type="hidden" name="zids" value="" />
        <input id="rids" type="hidden" name="rids" value="" />
        <input type="hidden" name="uid" value="{$uid}"/>
        <input type="submit" value="确认"/>
      </form>

    </div>
    <script>
      var userHZR = {$userHZR};
      var user = {1:[],2:[],3:[]};
      var hidden = {1:"hids",2:'zids',3:'rids'};
      for (var type in userHZR) {
        if (userHZR[type]){
          user[type] = userHZR[type].split(',');
          $("#"+hidden[type]).val(userHZR[type]);
        }
      }
      function clickLink(self){
        var display = $(self).attr("display");
        var o = {0:{display:1,todo:"show"},1:{display:0,todo:"hide"}};
        eval('$(self).attr("display",'+o[display].display+').next().next("ul").'+o[display].todo+'()');
      }
      
      function clickLevel1(self,ids,type){
        var check = $(self).attr('checked');
        if (check == true) {
          $(self).next().children().find("input").attr("checked",true).each(function(i,s){
            clickLevel2(s);
          });
        }else {
          $(self).next().children().find("input").attr("checked",false).each(function(i,s){
            clickLevel2(s);
          });
        } 
        //eval('$(self).next().children().find("input").attr("checked",'+$(self).attr("checked")+').each(function(i,s){clickLevel2(s)})');
      }

      function clickLevel2(self){
        var id = $(self).attr("cid");
        var type = $(self).attr("type_id");
        if ($(self).attr("checked") == true) {
          var count = 0;
          for(var i = 0; i < user[type].length; i++){
            if (user[type][i] == id) count = 1;
          }
          if (count == 0) user[type].push(id);
        }else {
          $(self).parent().parent().prev().attr('checked',false);
          for (var i = user[type].length - 1; i >= 0; i--) {
            if (user[type][i] == id) {
              user[type].splice(i,1);
              break;
            }
          }
        }
        user[type].sort();
        $("#"+hidden[type]).val(user[type].join(','));
      }
    </script>
  </body>
</html>
